﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Visifire.Charts;
using YFIN.View.PropertyServiceRef;
using YFIN.View.ViewModels;

namespace YFIN.View.Toolkit
{
    public partial class PropertyChart : ChildWindow
    {
        public PropertyChart(ObservableCollection<ModelPropertyType> propertyTypes)
        {
            InitializeComponent();
            CreateChart(propertyTypes);
        }
        public void CreateChart(ObservableCollection<ModelPropertyType> propertyTypes)
        {
            // Create a new instance of Chart
            Chart chart = new Chart();

            // Set the chart width and height
            chart.Width = 600;
            chart.Height = 450;
 
            // Create a new instance of Title
            Title title = new Title();

            // Set title property
            title.Text = "资产信息";

            // Add title to Titles collection
            chart.Titles.Add(title);

            // Create a new instance of DataSeries
            DataSeries dataSeries = new DataSeries();

            // Set DataSeries property
            dataSeries.RenderAs = RenderAs.Pie;

            // Create a DataPoint
            DataPoint dataPoint;

            foreach(var p in propertyTypes)
            {
                // Create a new instance of DataPoint
                dataPoint = new DataPoint();

                // Set YValue for a DataPoint
                dataPoint.AxisXLabel = p.Name;
                dataPoint.YValue = 0;
                foreach (var c in p.PropertyContents)
                {
                    dataPoint.YValue += c.MarketValue;
                }

                // Add dataPoint to DataPoints collection
                dataSeries.DataPoints.Add(dataPoint);
            }

            // Add dataSeries to Series collection.
            chart.Series.Add(dataSeries);

            // Add chart to LayoutRoot
            LayoutRoot.Children.Add(chart);
        }
    }
}
